<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="util.PreHandle,pojo.Student"%>
<%@page import="java.sql.SQLException"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'doLogin.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<%
		request.setCharacterEncoding("utf-8");
		String sname = request.getParameter("sname");
		String pass = request.getParameter("pass");
		String sql = "select * from student where sname=? and pass=?";
		Connection con = PreHandle.getConnection();
		PreparedStatement pstmt = null;
		ResultSet res = null;
		pstmt = con.prepareStatement(sql);
		pstmt.setString(1, sname);
		pstmt.setString(2, pass);
		res = pstmt.executeQuery();
		if (res.next()) {
			session.setAttribute("name", sname);
			session.setAttribute("st_id", res.getInt("stuno"));
			response.sendRedirect("Welcome.jsp");
		} else {
			response.sendRedirect("index.jsp");
		}
	%>
</body>
</html>
